package org.lee.strategy.app.event;

import org.lee.strategy.app.ICouponDiscount;

import java.math.BigDecimal;
import java.util.Map;

/**
 * MJCouponDiscount
 * 满减
 *
 * @author dralee
 * @date 2021-11-24 11:31:20
 **/
public class MJCouponDiscount implements ICouponDiscount<Map<String, String>> {

    /**
     * 满减
     * 1、满足x元后-n元，否则不减
     * 2、最低支付金额1元
     *
     * @param couponInfo: 券折扣信息：直减、满减，折扣、N元购
     * @param skuPrice:   sku金额
     * @return
     */
    @Override
    public BigDecimal discountAmount(Map<String, String> couponInfo, BigDecimal skuPrice) {
        String amount = couponInfo.get("amount");     // 满金额
        String discount = couponInfo.get("discount"); // 减的金额
        if (skuPrice.compareTo(new BigDecimal(amount)) < 0) { // 小于商品条件
            return skuPrice;
        }
        BigDecimal disCountAmount = skuPrice.subtract(new BigDecimal(discount));
        if (disCountAmount.compareTo(BigDecimal.ZERO) < 1) { // 最低要付1元
            return BigDecimal.ONE;
        }

        return disCountAmount;
    }
}
